<?php
$ip = current(swoole_get_local_ip());//公网访问需配置ip
return [
    'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
    'modules' => require(__DIR__ . '/modules.php'),
    'components' => [
        'assetManager' => [
            'class' => 'yii\swoole\web\AssetManager',
            'basePath' => '@runtime/assets',
            'baseUrl' => '/kmkl/runtime/assets'//反向代理需配置路由前缀
        ],
        'i18n' => [
            'translations' => [
                'custom' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@common/messages',
                    'sourceLanguage' => 'zh-CN',
                ],
            ],
        ],
        'db' => [
            'class' => 'yii\swoole\mysql\Connection',
            'dsn' => 'mysql:host=192.168.56.1;dbname=anhaoiot',
            'username' => 'root',
            'password' => 'root',
            'charset' => 'utf8',
            'enableSchemaCache' => true,
            'timeout' => 3,
            'tablePrefix' => 'anhao'
        ],
        'httpclient' => [
            'class' => 'yii\swoole\httpclient\Client',
            'requestConfig' => [
                'dns_timeout' => 1,
                'client_timeout' => 1,
            ],
        ],
        'redis' => [
            'class' => REDIS_POOL ? REDIS_POOL . '\Connection' : 'yii\redis\Connection',
            'hostname' => 'redis',
            'port' => 6379,
            'database' => 0,
            'unixSocket' => '/tmp/redis.sock'
        ],
        'cache' => [//使用共享内存做框架内部缓存
            'class' => SC_COM ? SC_COM . '\Cache' : 'yii\swoole\tablecache\Cache',
            'serializer' => ['\yii\swoole\helpers\SerializeHelper::serialize', '\yii\swoole\helpers\SerializeHelper::unserialize']
        ],
        'usercache' => [//用户缓存
            'class' => 'yii\swoole\redis\Cache',
            'serializer' => ['\yii\swoole\helpers\SerializeHelper::serialize', '\yii\swoole\helpers\SerializeHelper::unserialize']
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'isFlush' => false,
            'targets' => [
                [
                    'class' => \yii\swoole\log\FileTarget::class,
                    'levels' => ['error', 'warning'],
                    'logVars' => []
                ],
                [
                    'class' => \yii\swoole\log\FileTarget::class,
                    'logFile' => '@runtime/logs/http-request.log',
                    'categories' => ['yii\httpclient\*'],
                ],
            ],
        ],
        'rpc' => [
            'class' => \yii\swoole\rpc\RpcClient::class,
            'remoteList' => ['test' => ['TestLogic']],
            'selfList' => [],
            'config_r' => [//远程调用时的客户端
                'class' => \yii\swoole\rpc\TcpClient::class,
                'maxPoolSize' => 10,
                'busy_pool' => 5,
                'timeout' => 1
            ],
            'config_n' => [//本地反射调用
                'class' => \yii\swoole\rpc\NavClient::class
            ]
        ],
        'kafka' => [
            'class' => yii\swoole\kafka\Kafka::class,
            'socket' => [
                'class' => \yii\swoole\socket\SocketClient::class,
                'timeout' => 1
            ],
            'producer' => [
                'class' => \yii\swoole\kafka\KProducer::class,
                'refreshInterval' => 1000,
                'brokerList' => '127.0.0.1:9092',
                'brokerVersion' => '1.0.0',
                'requiredAck' => 1,
                'produceInterval' => 500
            ],
            'consumer' => [
                'class' => \yii\swoole\kafka\KConsumer::class,
                'refreshInterval' => 1000,
                'brokerList' => '127.0.0.1:9092',
                'groupId' => 'test',
                'brokerVersion' => '1.0.0',
                'topics' => ['test'],
                'offsetReset' => 'earliest',
                'targets' => [
                    'file' => [
                        'class' => \yii\swoole\kafka\Targets\FileTarget::class
                    ]
                ]
            ]
        ],
        'consul' => [
            'class' => \yii\swoole\consul\ConsulClient::class,
            'address' => 'http://consul',
            'port' => 8500
        ],
        'csconf' => [
            'class' => \yii\swoole\configcenter\ConsulConfig::class,
            'dc' => 'dc1'
        ],
        'gr' => [//服务治理
            'class' => \yii\swoole\governance\Governance::class,
            'tracer' => [
                'class' => \yii\swoole\governance\trace\Tracer::class
            ],
            'provider' => [
                'class' => \yii\swoole\governance\provider\ConsulProvider::class,
                'checkType' => \yii\swoole\governance\provider\ConsulProvider::HTTP,
                'register' => [
                    'Tags' => [],
                    'Address' => $ip,
                    'Port' => 9503,
                    'EnableTagOverride' => false,
                    'Check' => [
                        'tcp' => $ip . ':9503',
                        'interval' => sprintf('%ss', 10),
                        'timeout' => sprintf('%ss', 1),
                    ],
                ],
                'discovery' => [
                    'dc' => 'dc1',
                    'near' => '',
                    'tag' => '',
                    'passing' => true
                ]
            ],
            'balance' => [
                'class' => \yii\swoole\governance\balancer\BalancerSelecter::class,
                'defaultBalancer' => [
                    'class' => \yii\swoole\governance\balancer\RoundRobinBalancer::class
                ]
            ]
        ],
        'mqttclient' => [
            'class' => \yii\swoole\mqtt\MqttClientCtrl::class,
            'host' => '192.168.56.1',
            'port' => 1883,
            'username' => 'admin',
            'password' => '123456',
            'logger' => [
                'class' => \yii\swoole\mqtt\log\EchoLog::class,
                'log_level' => ['ERROR', 'DEBUG']
            ],
            'store' => [
                'class' => \yii\swoole\mqtt\store\MemStore::class,
            ]
        ],
        'timertask' => [
            'class' => \yii\swoole\timertask\TimerTask::class
        ]
    ],
    'language' => 'zh-CN',
    'timeZone' => 'Asia/Shanghai',
    'sourceLanguage' => 'en-US',
    'runtimePath' => dirname(dirname(__DIR__)) . '/runtime',
    'process' => require(__DIR__ . '/process.php'),
    'processPool' => require(__DIR__ . '/processpool.php'),
    'beforeStart' => require(__DIR__ . '/beforestart.php'),
    'workerStart' => require(__DIR__ . '/workerstart.php')
];
